package com.xiao.kafka.producer.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @Description kafka消息生产者，发送消息
 * @Auther: 笑笑是一个码农
 * @Date: 16:48 2021/1/6
 */
@Slf4j
@Component
public class KafkaProducer {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;


    public void send(String topic, String message){
        log.info("[ kafka生产者服务 ] 发送消息, topic: {}, message: {}", topic, message);
        kafkaTemplate.send(topic, message);
    }


    public void send(String topic, String key, String message){
        log.info("[ kafka生产者服务 ] 发送消息, topic: {}, key: {}, message: {}", topic, key, message);
        kafkaTemplate.send(topic, key, message);
    }

}
